import os, json
from download.downloadInterface import download_bp
from flask_cors import CORS, cross_origin
from utils.getTotalQuestion import *
from flask_sqlalchemy import SQLAlchemy
import logging.config
import configparser
from translate.TranslateFunction import *

os.environ['OPENROUTER_API_KEY'] = Config.OPENROUTER_API_KEY
app = Flask(__name__)
db = SQLAlchemy()

from user.SystemUser import *
from monitor.MonitorInfo import *
from report.ChatReport import *
from siteMessage.SiteMessage import *
from parseReport.AlipayInfo import *
from parseReport.WxpaInfo import *

if __name__ == '__main__':
    config = configparser.ConfigParser()
    config.read('logging_config.ini')

    # 根据配置初始化日志
    logging.config.fileConfig('logging_config.ini')
    from conversation.ConversationFunction import *
    from conversationDify.ConversationDify import *

    # 配置 Flask 应用

    CORS(app, resources=r'/*')
    app.config['SQLALCHEMY_DATABASE_URI'] = Config.SQLALCHEMY_DATABASE_URI
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = Config.SQLALCHEMY_TRACK_MODIFICATIONS
    app.config['SQLALCHEMY_ECHO'] = True
    db.init_app(app)  # 初始化 SQLAlchemy
    app.register_blueprint(conversation_bp)
    app.register_blueprint(sysUser_bp)
    app.register_blueprint(download_bp)
    app.register_blueprint(translate_bp)
    app.register_blueprint(siteMessage_bp)
    app.register_blueprint(conversation_dify_bp)
    app.register_blueprint(alipay_info_bp)
    app.register_blueprint(wx_info_bp)
    app.register_blueprint(monitor_info_bp)
    app.register_blueprint(chat_report)
    app.config['JSON_AS_ASCII'] = False
    app.run(debug=True, host='0.0.0.0', port=8080)
